home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 27.zip / BS1 part 27 / ImageMaster_d3.adf / piarc.lzh.parta / graphr.rexx < prev    next >
OS/2 REXX Batch file  |  1993-03-23  |  6KB  |  225 lines

  1. /*
  2.  * GRAPHr.rexx draw a GRAPH in the Image in IM
  3.  *
  4.  *  Written by: Barry Chalmers & Ben Williams
  5.  * Last Update: January 17th, 1992
  6.  *         For: Black Belt Systems image processing series IM, IM F/c, and IP.
  7.  * ---------------------------------------------------------------------------
  8.  *    Revision: 1.01 - see ReadMe file for details on changes to this level
  9.  */
  10.  
  11. call pragma('stack',20000);
  12. /*
  13.  * open rexxsupport.library -- needed for some functions
  14.  */
  15. if ~show('L',"rexxsupport.library") then do
  16.   if addlib('rexxsupport.library',0,-30,0) then do
  17.       /* everything's ok */
  18.     end;
  19.   else do
  20.     say 'We Have A Library Problem, Unable To Load "rexxsupport.library"';
  21.     say 'Cannot operate JPEG.rexx without this library - sorry!';
  22.     exit 10;
  23.     end;
  24.   end;
  25.  
  26. /*
  27.  * This will automatically direct the script to the proper
  28.  * software, if it is running. No matter where the script is
  29.  * launched from.
  30.  */
  31. prtnme = 'IP_Port'; /* assume Image Professional */
  32. if show('P','IP_Port') = 0 then do
  33.   if show('P','IM_Port') = 0 then do
  34.     say "Can't find image processor's ARexx port!!!"; /* not running? */
  35.     say "This script requires IP, IM or IM F/c to run!";
  36.     exit(20);
  37.     end;
  38.   else do
  39.     prtnme = 'IM_Port'; /* That's the thing about assumptions... */
  40.     end;                 /* We make em, user's break em.          */
  41.   end;
  42.  
  43.   /*
  44.    * This code attempts to read a file called "picmdpath" from REXX:
  45.    * If it can't find it, the script will assume that the commands
  46.    * associated with this PI Module are in "c:". If the file exists,
  47.    * the script will look in the path that is specified in the file.
  48.    * If you create this file, you MUST put a complete, correct path
  49.    * in it; if the commands are in a sub-directory, you have to put
  50.    * the trailing slash on the path (like, device:dir/).
  51.    * 
  52.    */
  53.   cmdpath = 'c:';
  54.   if open(fhandle,'rexx:picmdpath','read') then  /* open the file */
  55.     do
  56.       cmdpath = readln(fhandle);
  57.       call close(fhandle);  /* close the file    */
  58.     end
  59.  
  60. /*
  61.  * Get the file name parts
  62.  */
  63.   prevpath = 'ram:';
  64.   if show('C',graphpath) = 1 then do
  65.     prevpath = getclip(graphpath);
  66.     end;
  67.   prevname = 'image';
  68.   if show('C',graphname) = 1 then do
  69.     prevname = getclip(graphname);
  70.     end;
  71.   prevext = '.table';
  72.   if show('C',graphext) = 1 then do
  73.     prevext = getclip(graphext);
  74.     end;
  75.   width = 320;
  76.   if show('C',graphwidth) = 1 then do
  77.     width = getclip(graphwidth);
  78.     end;
  79.   height = 200;
  80.   if show('C',graphheight) = 1 then do
  81.     height = getclip(graphheight);
  82.     end;
  83.  
  84.  
  85. address(prtnme);
  86.  
  87.     options results;
  88.     'filerequest "'||prevpath||'" "'||prevname||'" "'||prevext||'" '||'"Get Table"';
  89.     graphfile = result;
  90.     options;
  91.     call checkfile(graphfile);
  92.     
  93.     options results;
  94.     'asknumber "Width (X)","'||width;
  95.     width = result;
  96.     options;
  97.     call setclip(graphwidth,width);
  98.     
  99.     options results;
  100.     'asknumber "Height (Y)","'||height;
  101.     height = result;
  102.     options;
  103.     call setclip(graphheight,height);
  104.  
  105.     'autoredraw 0';
  106.     'newasprimary '||width||' '||height;
  107.  
  108. options results;
  109. 'jackin';
  110. stuff = result;
  111.  
  112. 'current';
  113. bufdata = result;
  114.  
  115. options;
  116.  
  117. parse var bufdata bname ',' bnum ',' brest
  118.  
  119. 'lockimage '||bnum;
  120. address command cmdpath||'graph '||stuff||' '||graphfile;
  121. 'unlockimage '||bnum;
  122. address(prtnme);
  123.  
  124. 'tofront';
  125. 'redraw';
  126.  
  127. address;
  128.  
  129. exit 0;
  130.  
  131.  
  132. checkfile: 
  133. arg thefile;
  134.   if thefile = 'FR_CANCELLED' then do
  135.     'tofront';
  136.     exit 0;
  137.     end;
  138.   prevpath = gimmepath(thefile);
  139.   call setclip(graphpath,prevpath);
  140.   prevname = gimmename(thefile);
  141.   call setclip(graphname,prevname);
  142.   prevext  = gimmeext(thefile);
  143.   call setclip(graphext,prevext);
  144.   return;
  145.   end
  146.  
  147. /*
  148.  * gimmepath
  149.  *
  150.  * This takes the provided argument and sucks the path out of it, then
  151.  * returns that path to the caller, sans file name.
  152.  */
  153. gimmepath:
  154.   arg fullnamegx;
  155.     tempgx = reverse(fullnamegx);
  156.     lengx = length(fullnamegx);   /* get length of string */
  157.     slashdex = index(tempgx,'/'); /* first occurance of '/' from right */
  158.     colondex = index(tempgx,':');  /* first occurance of ':' from right */
  159.     seploc = 0; /* assumes current dir, no path supplied */
  160.     if slashdex ~= 0 then do /* we assume we are in a DIR */
  161.       seploc = (lengx - slashdex)+1;
  162.       end;
  163.     else do
  164.       if colondex ~= 0 then do /* we assume we are on a device */
  165.         seploc = (lengx - colondex)+1;
  166.         end;
  167.       end;
  168.   gxname = substr(fullnamegx,seploc+1); /* if you ever need it */
  169.   gxpath = left(fullnamegx,seploc);
  170.   return(gxpath);
  171.   end
  172.  
  173.  
  174. gimmename:
  175.   arg fullnamegx;
  176.     tempgx = reverse(fullnamegx);
  177.     lengx = length(fullnamegx);   /* get length of string */
  178.     slashdex = index(tempgx,'/'); /* first occurance of '/' from right */
  179.     colondex = index(tempgx,':');  /* first occurance of ':' from right */
  180.     seploc = 0; /* assumes current dir, no path supplied */
  181.     if slashdex ~= 0 then do /* we assume we are in a DIR */
  182.       seploc = (lengx - slashdex)+1;
  183.       end;
  184.     else do
  185.       if colondex ~= 0 then do /* we assume we are on a device */
  186.         seploc = (lengx - colondex)+1;
  187.         end;
  188.       end;
  189.   extpos = lastpos(".",fullnamegx) - 2;
  190.   if extpos > seploc then do
  191.     gxname = substr(fullnamegx,seploc+1,extpos-seploc+1);
  192.     end;
  193.   else do
  194.     gxname = substr(fullnamegx,seploc+1);
  195.     end;
  196.   return(gxname);
  197.   end
  198.  
  199.  
  200. gimmeext:
  201.   arg fullnamegx;
  202.     tempgx = reverse(fullnamegx);
  203.     lengx = length(fullnamegx);   /* get length of string */
  204.     slashdex = index(tempgx,'/'); /* first occurance of '/' from right */
  205.     colondex = index(tempgx,':');  /* first occurance of ':' from right */
  206.     seploc = 0; /* assumes current dir, no path supplied */
  207.     if slashdex ~= 0 then do /* we assume we are in a DIR */
  208.       seploc = (lengx - slashdex)+1;
  209.       end;
  210.     else do
  211.       if colondex ~= 0 then do /* we assume we are on a device */
  212.         seploc = (lengx - colondex)+1;
  213.         end;
  214.       end;
  215.   extpos = lastpos(fullnamegx,'.');
  216.   if extpos > seploc then do
  217.     gxext = substr(fullnamegx,extpos+1);
  218.     end
  219.   else do
  220.     gxext = '';
  221.     end
  222.   return(gxext);
  223.   end
  224.  
  225.